package com.guqinghan.guqinghan_02_systemfile.utils;

import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.util.Log;

import androidx.core.app.ActivityCompat;

/*
 自定义动态权限类，如果要加权限就在这里继续加就可以了
 */
public class PermisionUtils {
    /*
     如果app没有as卡存储权限，则动态申请
     */
    public static void  verifyStoragePermission(Activity activity){
        // 检查是否拥有写权限
        int permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE);
        if (permission != PackageManager.PERMISSION_GRANTED){
            // 没有权限询问用户授权
            Log.i("user","动态申请权限");
            ActivityCompat.requestPermissions(activity,new String[]{
                    Manifest.permission.READ_EXTERNAL_STORAGE,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE
            },1);
        }
    }

}
